<template>
  <!-- 添加或修改舱单系统申报认证对话框 -->
  <el-dialog :title="title" :visible.sync="dialogVisible" width="1000px" append-to-body :close-on-click-modal="false"
    @close="close">
    <el-form ref="form" :model="form" :rules="rules" label-width="130px" label-position="right" size="mini" class="flex-form">

     <el-form-item label="企业代码" prop="enterpirceCoed">
       <el-input v-model.trim="form.enterpirceCoed" :disabled="true" placeholder="请输入企业代码" />
     </el-form-item>
     <el-form-item label="企业名称" prop="enterpriceName">
       <el-input v-model.trim="form.enterpriceName" :disabled="true" placeholder="请输入企业名称" />
     </el-form-item>
     <!-- <el-form-item label="用户名" prop="userName">
        <el-input v-model.trim="form.userName" placeholder="请输入用户名" />
      </el-form-item>
      <el-form-item label="身份证号码" prop="idNo">
        <el-input v-model.trim="form.idNo" placeholder="请输入身份证号码" />
      </el-form-item> -->
      <el-form-item label="舱单传输人代码" prop="msgRepCode">
        <el-input v-model.trim="form.msgRepCode" placeholder="请输入舱单传输人代码" />
      </el-form-item>
      <el-form-item label="舱单传输人名称" prop="msgRepName">
        <el-input v-model.trim="form.msgRepName" placeholder="请输入舱单传输人名称" />
      </el-form-item>
      <el-form-item label="企业备案关区" prop="masterCustoms">
        <el-input v-model.trim="form.masterCustoms" placeholder="请输入传输企业备案关区" />
      </el-form-item>
      <el-form-item label="认证类型" prop="type">
        <el-select v-model.trim="form.type" placeholder="请选择认证类型">
          <el-option v-for="(item, index) in dict.type.mft_auth_type" :key="index" :label="item.label"
            :value="item.value"></el-option>
        </el-select>
      </el-form-item>
      <el-form-item label="申报系统类型" prop="declWayType">
        <el-select v-model.trim="form.declWayType" placeholder="请选择申报系统类型">
          <el-option v-for="(item, index) in dict.type.mft_decl_sys_type" :key="index" :label="item.label"
            :value="item.value"></el-option>
        </el-select>
      </el-form-item>
      <el-form-item label="导入客户端代码" prop="importClientCode">
        <el-input v-model.trim="form.importClientCode" placeholder="请输入导入客户端代码" />
      </el-form-item>
      <el-form-item label="理货/运抵场所" prop="fieldCode">
        <el-input v-model.trim="form.fieldCode" placeholder="请输入理货/运抵场所代码" />
      </el-form-item>
      <el-form-item label="理货公司代码" prop="talCompanyCode">
        <el-input v-model.trim="form.talCompanyCode" placeholder="请输入理货公司代码" />
      </el-form-item>
      <el-form-item label="理货责任人名称" prop="talMasterName">
        <el-input v-model.trim="form.talMasterName" placeholder="请输入理货责任人名称" />
      </el-form-item>
      <el-form-item label="企业备案ID" prop="eastPortEntId">
        <el-input v-model.trim="form.eastPortEntId" placeholder="请输入企业备案" />
      </el-form-item>
      <el-form-item label="操作员卡号" prop="operCardNo">
        <el-input v-model.trim="form.operCardNo" placeholder="请输入操作员卡号" />
      </el-form-item>
    </el-form>
    <div slot="footer" class="dialog-footer">
      <el-button type="primary" @click="submitForm">确 定</el-button>
      <el-button @click="close">取 消</el-button>
    </div>
  </el-dialog>
</template>
<script>
  import {
     getEntInfo,
    getMftDeclAccountInfo,
    addMftDeclAccountInfo,
    updateMftDeclAccountInfo
  } from "@/api/swdecl/mftDeclAccountInfo";
  export default {
    name: "MftDeclAccountInfo-addEdit",

    props: {
      dialogType: {
        type: String,
        default: "add",
      },
      rowData: {
        type: Object,
        default: () => {},
      },
      dict: {}
    },
    data() {
      return {
        // 弹出层
        dialogVisible: false,
        // 标题
        title: "新增",
        // 表单参数
        form: {
          id: null,
          userName: null,
          idNo: null,
          msgRepCode: null,
          msgRepName: null,
          type: null,
          declWayType: null,
          enterpirceCoed: null,
          enterpriceName: null,
          masterCustoms: null,
          importClientCode: null,
          talCompanyCode: null,
          talMasterName: null,
          createBy: null,
          createTime: null,
          eastPortEntId:null,
          operCardNo:null
        },
        // 舱单系统申报认证表格数据
        mftDeclAccountInfoList: [],
        // 表单校验
        rules: {
          msgRepCode: [
            {
              type: "string",
              required: true,
              message: "舱单传输人代码不能为空",
              trigger: "blur",
            },
          ],
          msgRepName: [
            {
              type: "string",
              required: true,
              message: "舱单传输人名称不能为空",
              trigger: "blur",
            },
          ],
          masterCustoms: [
            {
              type: "string",
              required: true,
              message: "传输企业备案关区不能为空",
              trigger: "blur",
            },
          ],
          type: [
            {
              type: "string",
              required: true,
              message: "认证类型不能为空",
              trigger: "blur",
            },
          ],
          declWayType: [
            {
              type: "string",
              required: true,
              message: "申报系统类型不能为空",
              trigger: "blur",
            },
          ],
          importClientCode: [
            {
              type: "string",
              required: true,
              message: "导入客户端代码不能为空",
              trigger: "blur",
            },
          ],
        }
      };
    },
    methods: {
      open() {
        this.dialogVisible = true;
        this.$nextTick(() => {
          if (this.dialogType == "add") {
            this.title = "新增";
            this.loadEntInfo();
          } else if (this.dialogType == "edit") {
            this.title = "编辑";
            this.loadDetail();
            this.loadEntInfo();
          } else if (this.dialogType == "detail") {
            this.title = "详情";
            this.loadDetail();
            this.loadEntInfo();
          }
        });
      },
      close() {
        this.$refs["form"].resetFields();
        this.dialogVisible = false;
      },
      // 获取详情
      loadDetail() {
        const id = this.rowData.id;
        getMftDeclAccountInfo(id).then((res) => {
          if (res.code == 200) {
            this.form = res.data;
          }
        });
      },
      loadEntInfo(){
        getEntInfo().then((res) => {
          if (res.code == 200) {
            this.form = res.data;
          }
        });
      },

      // 提交表单
      submitForm() {
        this.$refs["form"].validate(valid => {
          if (valid) {
            let params = {
              ...this.form,
            };
            if (this.dialogType == "add") {
              addMftDeclAccountInfo(this.form).then(res => {
                if (res.code === 200) {
                  this.$modal.msgSuccess("新增成功");
                  this.close();
                  this.$emit("handleQuery");
                }
              });
            } else {
              params.id = this.rowData.id;
              updateMftDeclAccountInfo(this.form).then(res => {
                if (res.code === 200) {
                  this.$modal.msgSuccess("修改成功");
                  this.close();
                  this.$emit("handleQuery");
                }
              });
            }
          }
        });
      },
    },
  };
</script>

<style lang="scss" scoped></style>
